package com.wen.jwtdemo.controller;

import com.wen.jwtdemo.common.JwtUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class DemoController {
    /**
     * 用于测试老式保存用户的方法   客户端cookie  服务端  session存储
     * @param request
     * @param name
     * @return
     */
    @GetMapping()
    @RequestMapping("/demo/testSession")
    public String testSession(HttpServletRequest request,String name){
        request.getSession().setAttribute("name",name);
        return "hrrlo";
    }


    @PostMapping()
    @RequestMapping("/demo/login")
    public String login(String name){
        Map<String,String> map = new HashMap<>();
        map.put("name",name);
        return JwtUtils.getToketn(map);
    }

    @PostMapping()
    @RequestMapping("/demo/getMsg")
    public String getMsg(String token){
     //do something
        return "ok";
    }

}
